﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DataProcess
{
    public partial class frmMDI : Form
    {
        public frmMDI()
        {
            InitializeComponent();
#if IS_BASE || IS_ALL
			var tsmi_LitterConvert = new ToolStripMenuItem();
			tsmi_LitterConvert.Text = "英文首字母大小写转换";
			tsmi_LitterConvert.Click += new System.EventHandler(this.英文首字母转换ToolStripMenuItem_Click);
			var tsmi_DataCompare = new ToolStripMenuItem();
			tsmi_DataCompare.Text = "成分数据对比";
			tsmi_DataCompare.Click += new System.EventHandler(this.数据对比ToolStripMenuItem_Click);
			var tsmi_AddNames = new ToolStripMenuItem();
			tsmi_AddNames.Text = "批量添加名称";
			tsmi_AddNames.Click += new System.EventHandler(this.批量增加商品名ToolStripMenuItem_Click);
			menuStrip1.Items.AddRange(new ToolStripMenuItem[] { tsmi_LitterConvert, tsmi_DataCompare, tsmi_AddNames });
#endif
#if IS_UPTODATE || IS_ALL
			var tsmi_XmlToAccess = new ToolStripMenuItem();
			tsmi_XmlToAccess.Text = "XML转换";
			tsmi_XmlToAccess.Click += new System.EventHandler(this.xML转数据库ToolStripMenuItem_Click);
			var tsmi_WordReplace = new ToolStripMenuItem();
			tsmi_WordReplace.Text = "处理word";
			tsmi_WordReplace.Click += new System.EventHandler(this.处理wordToolStripMenuItem_Click);
			menuStrip1.Items.AddRange(new ToolStripMenuItem[] { tsmi_XmlToAccess, tsmi_WordReplace});
#endif
#if IS_PI || IS_ALL
            var tsmi_Pi = new ToolStripMenuItem();
            tsmi_Pi.Text = "说明书字数统计";
            tsmi_Pi.Click += tsmi_Pi_Click;
            menuStrip1.Items.Add(tsmi_Pi);
#endif
#if IS_DEV || IS_ALL
			var tsmi_ColorTest = new ToolStripMenuItem();
			tsmi_ColorTest.Text = "颜色测试";
			tsmi_ColorTest.Click += new System.EventHandler(this.颜色测试ToolStripMenuItem_Click);
			menuStrip1.Items.Add(tsmi_ColorTest);
#endif
#if IS_MCDEX || IS_ALL
            var tsmi_chm = new ToolStripMenuItem();
            tsmi_chm.Text = "中药材";
            tsmi_chm.Click += tsmi_chm_Click;
            menuStrip1.Items.Add(tsmi_chm);
#endif

        }

        void tsmi_chm_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmCHM)))
            {
                frmCHM frm = new frmCHM();
                frm.WindowState = FormWindowState.Maximized;
                frm.MdiParent = this;
                frm.Show();
            }
        }

        void tsmi_Pi_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmPiWordsTotal)))
            {
                frmPiWordsTotal frm = new frmPiWordsTotal();
                frm.WindowState = FormWindowState.Maximized;
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void 英文首字母转换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmLetterConversion)))
            {
                frmLetterConversion lc = new frmLetterConversion();
                lc.WindowState = FormWindowState.Maximized;
                lc.MdiParent = this;
                lc.Show();
            }
        }

        private void xML转数据库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmXmlToAccess)))
            {
                frmXmlToAccess xmlToAccess = new frmXmlToAccess();
                xmlToAccess.WindowState = FormWindowState.Maximized;
                xmlToAccess.MdiParent = this;
                xmlToAccess.Show();
            }
        }

        private void 处理wordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmWordReplace)))
            {
                frmWordReplace word = new frmWordReplace();
                word.WindowState = FormWindowState.Maximized;
                word.MdiParent = this;
                word.Show();
            }
        }

        private void 颜色测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmColor)))
            {
                frmColor color = new frmColor();
                color.WindowState = FormWindowState.Maximized;
                color.MdiParent = this;
                color.Show();
            }
        }

        private void 数据对比ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmDataCompare)))
            {
                frmDataCompare dc = new frmDataCompare();
                dc.WindowState = FormWindowState.Maximized;
                dc.MdiParent = this;
                dc.Show();
            }
        }

        private void 批量增加商品名ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(frmAddBrandName)))
            {
                frmAddBrandName abn = new frmAddBrandName();
                abn.WindowState = FormWindowState.Maximized;
                abn.MdiParent = this;
                abn.Show();
            }

        }

        private bool Exists(Type type)
        {
            foreach (var item in MdiChildren)
            {
                if (item.GetType() == type)
                {
                    item.Activate();
                    return true;
                }
            }
            return false;
        }

        private void tsmiProduct_Click(object sender, EventArgs e)
        {
            if (!Exists(typeof(ProductForm)))
            {
                ProductForm abn = new ProductForm();
                abn.WindowState = FormWindowState.Maximized;
                abn.MdiParent = this;
                abn.Show();
            }
        }
    }
}
